"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/3/6 9:48
@Description : json格式数据操作
列表中嵌套字典
在实际应用中常见的数据格式 [{},{},{}]
"""
student_list = [
    {
        'id': 1,
        'student_name': '张三',
        'score': 90
    }, {
        'id': 2,
        'student_name': '李四',
        'score': 80
    }, {
        'id': 3,
        'student_name': '王五',
        'score': 70
    }
]

import json
#  写出
'''
json_str = json.dumps(student_list)
with open('dir01/students.json', 'w') as f:
    f.write(json_str)
'''

# 读取
with open('dir01/students.json', 'r') as f:
    str_students = f.read()
    students_list_data = json.loads(str_students)
    print(students_list_data,type(students_list_data))
    for student in students_list_data:
        for key, value in student.items():
            print(key,value)


